package ch03.Design;


import ch03.Impl.NewsDaoMySqlImpl;
import ch03.Impl.NewsDaoOracleImpl;
import ch03.Impl.NewsDaoRedisImpl;
import ch03.dao.NewsDao;

public class SimpleDaoFactory {
    /**
     * 创建NewsDao实例工厂类
     */
    public static NewsDao getInstance(String key){
        switch (key){
            case "mysql":
                return new NewsDaoMySqlImpl();
            case "oracle":
                return new NewsDaoOracleImpl();
            case "return" :
                return new NewsDaoRedisImpl();
            default:
                throw new RuntimeException("无效的数据库类型："+key + ",DAO获取失败");
        }
    }

}
